<template>
  <ul class="app-header-nav">
    <li class="home">
      <router-link to="/">首页</router-link>
    </li>
    <li v-for="item in list"
      :key="item.id"
      @mouseenter="open(item)"
      @mouseleave="hide(item)">
      <router-link :to="`/category/${item.id}`"
        @click="hide(item)">{{item.name}}</router-link>
      <div class="layer"
        :class="{open:item.open}">
        <ul>
          <li v-for="i in item.children"
            :key="i.id">
            <router-link :to="`/category/sub/${i.id}`"
              @click="hide(item)">
              <img :src="i.pictrue"
                alt="">
              <p>{{i.name}}</p>
            </router-link>
          </li>
        </ul>
      </div>
    </li>
    <!-- <li><a href="#">餐厨</a></li>
    <li><a href="#">艺术</a></li>
    <li><a href="#">电器</a></li>
    <li><a href="#">居家</a></li>
    <li><a href="#">洗护</a></li>
    <li><a href="#">孕婴</a></li>
    <li><a href="#">服装</a></li>
    <li><a href="#">杂货</a></li> -->
  </ul>

</template>

<script>
import { mapState, mapMutations } from 'vuex'
export default {
  name: 'app-header-nav',
  computed: {
    ...mapState('category', ['list'])
  },
  methods: {
    ...mapMutations('category', ['open', 'hide'])
  }
}
</script>

<style lang="less" scoped>
.app-header-nav {
  width: 820px;
  display: flex;
  justify-content: space-around;
  padding-left: 40px;
  position: relative;
  // 加上 >
  > li {
    margin-right: 40px;
    width: 38px;
    text-align: center;
    // 加上 >
    > a {
      font-size: 16px;
      line-height: 32px;
      height: 32px;
      display: inline-block;
    }
    &:hover {
      // 加上 >
      > a {
        color: @xtxColor;
        border-bottom: 1px solid @xtxColor;
      }
      // > .layer {
      //   height: 124px;
      //   opacity: 1;
      // }
    }
  }
}
.layer {
  &.open {
    height: 124px;
    opacity: 1;
  }
  width: 1240px;
  background-color: #fff;
  position: absolute;
  left: -200px;
  top: 56px;
  height: 0;
  overflow: hidden;
  opacity: 0;
  box-shadow: 0 0 5px #ccc;
  transition: all 0.2s 0.1s;
  ul {
    display: flex;
    flex-wrap: wrap;
    padding: 0 70px;
    align-items: center;
    height: 124px;
    li {
      width: 110px;
      text-align: center;
      img {
        width: 60px;
        height: 60px;
      }
      p {
        padding-top: 10px;
      }
      &:hover {
        p {
          color: @xtxColor;
        }
      }
    }
  }
}
</style>
